//<script type='text/javascript'>

	/////// BASE WIN CLASS
	var Win = function (id, vars) {
		
		if( !id ) id = "asset." + ( dashboard.date.getTime() + Math.random());
		
		if($(id)) obj = $(id);
		else Object.extend(obj = new Element("div", {id:id, class:"win pearl"}), win.object);
		obj.vars = (vars)? vars : {};
		win.all[id] = obj;
				
		if(obj.vars.seed) obj.seed(obj.vars.seed);
		obj.observe("mouseover", controls.bubble ); //
		return obj;
	}
	
	//////////////////////////////////////////	 WIN OBJECT
	var win = {
		all			: {},
		object		: {
			objtype	: "win",
			request	: function( param ) {
				Object.extend( param, { trg:this.id });
				if(param.vars) Object.extend(this.vars, param.vars);
				xhttp.send('control.call.php', param);
				
				dashboard.user.logtime(init.session);
				return this;
			},
			
			seed	: function(input, n ) {
				this.update(cont = new Element("div", {id:this.id+".cont"}))
				if( input[0] ) input.each( function(el){ cont.insert(el) } );
				else cont.insert( input );
				
				if( !n ) new Effect.Highlight( cont, { startcolor:'#ffffff', duration:2 });
				
			},
						
			comment	: function(message, fx) {
				if($(this.id + ".comment")) xhttp.gfx(message, this.id + ".comment", fx); 
				else $('dashboard').insert( new Bubble( message ) );
				return this;
			}
		}
	};

	win.asset = {
		
		// GROUP OBJECT
		group	: {
			build	: function(vars) {
				form = elBirth("form", {id:vars.id+".form",style:"display:none;"}, vars.cont);
				$(vars.id).className = "group";
				$(vars.id).appendChild(new Element("font", {'id':vars.id+".comment",'class':"comment"}));
				$(vars.id).appendChild(new Element("font", {id:vars.id+".toggle", class:"name"})).update(vars.descr);
				$(vars.id).appendChild(form);
				//$(vars.id).appendChild(new Element("div", {'id':vars.id+".comment",'class':"comment"}));
				if(vars.class) $(vars.id).addClassName(vars.class);
				//$(vars.id).insert({after:new Element("div", {'id':vars.id+".comment",'class':"comment"})});
				
				$(vars.id+".toggle").observe("click",function(e){
					$(this.parentNode.id+".form").toggle();
					this.toggleClassName("toggle mini");
				});
				if(vars.open) {
					$(vars.id+".form").show();
					$(vars.id+".toggle").toggleClassName("toggle mini");
				}
				
			}
		},

		fetchcontent: function(bt) {
			vars = new Object(); noreturn = false;
			bt.parentNode.childElements().each(function(child,id){
				if(child.className.startsWith('txtfield')){ vtxt = win.asset.txtfield.list[child.id];
					for(l in vtxt.lang) vtxt.lang[l] = vtxt.lang[l];
					vars[vtxt.ref] = vtxt.lang;
					if(vtxt.req && !$H(vtxt.lang).keys().length){ noreturn=vtxt.ref; win.asset.addcomment(child.id+".comment", "please finish this"); }
					if(vtxt.objid) vars.id = vtxt.objid;//vars[vtxt.ref].id = vtxt.objid;
				}
				if(child.className.startsWith('dropbox')){ vdrop = win.asset.dropbox.list[child.id+".box"]; 
					if(vdrop.floats.size() > vdrop.initfloats.size()){
						vars[(vdrop.ref)?vdrop.ref:vdrop.descr] = [];
						vdrop.floats.each(function(key){ if(!vdrop.initfloats.include(key)) {
							vars[(vdrop.ref)?vdrop.ref:vdrop.descr].push({id:win.float.list[key].id, type:win.float.list[key].type});
						}});	
						
					}
					//vars[(vdrop.ref)?vdrop.ref:vdrop.descr] = vdrop.obj;
					if(vdrop.req && !$H(vdrop.obj).keys().length){ noreturn=vdrop.ref; win.asset.addcomment(child.parentNode.id+".comment", "please finish this"); }
				} 
			});
			if(!noreturn) return vars;
		},
		addcomment	: function(trg,input,prevail) {
			if(typeof input == "string") if(prevail) $(trg).innerHTML += input; else $(trg).update(input); 
			else if(prevail) $(trg).appendChild(input); else { $(trg).update(); $(trg).appendChild(input); }
			new Effect.Highlight((typeof input == "string")? trg:input, {startcolor:"#fedb4e",endcolor:"#f9f7f7",restorecolor:"#f9f7f7",duration:1});
		}
	}
